//
//  SecondViewController.m
//  3DTouch
//
//  Created by 蒋林 on 15/12/8.
//  Copyright © 2015年 蒋林. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController () <UIPreviewActionItem>

@end

@implementation SecondViewController

- (instancetype)initWithTitle:(NSString *)title backgroundColor:(UIColor *)backgroundColor {
    if (self = [super init]) {
        self.title = title;
        self.view.backgroundColor = backgroundColor;
        
        UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        backgroundImage.image = [UIImage imageNamed:@"1"];
        [self.view addSubview:backgroundImage];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
        imageView.image = [UIImage imageNamed:@"window2.jpg"];
        [self.view addSubview:imageView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 300, self.view.frame.size.width - 20, 50)];
        label.textAlignment = NSTextAlignmentCenter;
        label.font =[UIFont systemFontOfSize:16];
        label.text = @"3D Touch功能简单使用\n以一种自己的认为好的方式分享给大家";
        label.numberOfLines = 2;
        label.textColor = [UIColor orangeColor];
        [self.view addSubview:label];
        
        
        UILabel *add = [[UILabel alloc] initWithFrame:CGRectMake(10, self.view.frame.size.height - 120, self.view.frame.size.width - 20, 30)];
        add.textAlignment = NSTextAlignmentCenter;
        add.font =[UIFont boldSystemFontOfSize:26];
        add.text = @"组织等你加入: 250574085";
        [self.view addSubview:add];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (NSArray<id<UIPreviewActionItem>> *)previewActionItems
{
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"First Item" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"what's this First Item");
        [self showAlertWithMessage:@"Mr DoubleMu is very handsome"];
    }];
    UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Second Item" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"what's this Second Item");
        [self showAlertWithMessage:@"So Cool, Man！"];
    }];
    UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"Third Item" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"what's this Third Item");
        [self showAlertWithMessage:@"This Demo is for reference only."];
    }];
    UIPreviewAction *action4 = [UIPreviewAction actionWithTitle:@"Fourth Item" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"what's this Fourth Item");
        [self showAlertWithMessage:@"I'm very handsome, really？"];
    }];
    
    [array addObject:action1];
    [array addObject:action2];
    [array addObject:action3];
    [array addObject:action4];
    
    return array;
}

- (void)showAlertWithMessage:(NSString *)message {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Prompt" message:message delegate:self cancelButtonTitle:@"Agreed" otherButtonTitles:@"Yes", nil];
    [alert show];
}

@end
